<?php

namespace app\api\logic;

use app\common\library\RedissLock;
use app\common\service\TiktokPackageApiService;
use app\data\util\HttpUtil;
use app\data\util\MqQueueName;
use app\systems\logic\MqTaskPushLogic;
use think\facade\Db;

class TestOrderLogic extends BasicLogic
{


    /**
     * @desc   测试获取计算费用生产
     * @date   2024-09-16
     * @author 2024-09-16
     */
    public function get_settlement_produce(){
           $where= [];
           $where[]= ['settlement_amount','=',''];
           $start_date = strtotime(date('Y-m-d 00:00:00', time()-16*3600-7*24*3600));
           $end_date   = strtotime(date('Y-m-d 23:59:59', time()-16*3600));
           $where[]    = ['createtime','between', [$start_date, $end_date]];
           $list = Db::name('order')->field('order_id,shop_id')->where($where)->select();
           $list = objectToArray($list);
           if($list){
            foreach($list as $v){
                //数据推送到队列处理
                MqTaskPushLogic::mq_task_push(
                    '',
                    MqQueueName::QUEUE_ORDER_SETTLEMENT_AMOUNT_QUEUE,
                    [
                        'shop_id'        =>$v['shop_id'],
                        'order_id'       =>$v['order_id'],
                    ],
                    false
                );
            }
        }
        return $this->jsonMessage(200, '操作成功',null);
    }









    /**
     * @desc   测试获取计算费用 settlement_amount
     * @date   2024-09-16
     * @author 2024-09-16
     */
    public function get_settlement_consumer($info){
        //并发处理;
        $redis_lock = new RedissLock();
        $key        = 'shipping_fee_consumer:'.time();
        $lock       = $redis_lock::lock($key, $redis_lock::UNBLOCK, 400);
        if (!$lock) {
           return ['code'=>201,'msg'=>'数据并发了'];
        }
        htmlLog(['data'=>$info],OPERATE_LOG . date('Ym') . '/get_settlement_consumer/' . date('Ymd') . '.txt');
        //调用接口
        (new TiktokPackageApiService())->get_settlement_amount($info);
        $lock->unlock();
        return true;
    }



}